package io.github.talelin.latticy.controller.v1;


import io.github.talelin.core.annotation.LoginRequired;
import io.github.talelin.core.annotation.PermissionModule;
import io.github.talelin.latticy.dto.omsware.OmsCheckDTO;
import io.github.talelin.latticy.dto.userware.UpdateUserwareDTO;
import io.github.talelin.latticy.service.OmsUserwareService;
import io.github.talelin.latticy.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.github.talelin.latticy.model.OmsUserwareDO;

import javax.validation.constraints.Min;
import javax.validation.constraints.Max;
import javax.validation.constraints.Positive;

import java.util.List;

/**
* @author generator@wulongbo
* @since 2022-05-30
*/
@RestController
@RequestMapping("/v1/oms-userware")
@PermissionModule(value = "oms用户仓库管理")
@Validated
public class OmsUserwareController {

    @Autowired
    private OmsUserwareService omsUserwareService;

    @PostMapping("")
    public CreatedVO create() {
        return new CreatedVO();
    }

    @DeleteMapping("/{id}")
    public DeletedVO delete(@PathVariable @Positive(message = "{id.positive}") Integer id) {
        return new DeletedVO();
    }

    @LoginRequired
    @GetMapping("/{id}")
    public List<WarehouseVO> getOmsWarehouseById(@PathVariable(value = "id") @Positive(message = "{id.positive}") Integer id) {
        return omsUserwareService.getWareNameListByOmsUserId(id);
    }

    @LoginRequired
    @GetMapping("/getAllWarehouseByOmsRoot")
    public List<WarehouseVO> getAllWarehouseByOmsRoot() {
        return omsUserwareService.getAllWarehouseByOmsRoot();
    }

    @LoginRequired
    @PutMapping("")
    public UpdatedVO update(@RequestBody @Validated UpdateUserwareDTO updateUserwareDTO) {
        omsUserwareService.updateOmsUserware(updateUserwareDTO);
        return new UpdatedVO();
    }

    /**
     * feign调用接口，校验仓库编码是否存在
     * @param dto
     * @return
     */
    @PostMapping("/checkWareExistByCode")
    public boolean checkWareExistByCode(@RequestBody @Validated OmsCheckDTO dto) {
        return omsUserwareService.checkWareExistByCode(dto);
    }

    @GetMapping("/page")
    public PageResponseVO<OmsUserwareDO> page(
            @RequestParam(name = "page", required = false, defaultValue = "0")
            @Min(value = 0, message = "{page.number.min}") Integer page,
            @RequestParam(name = "count", required = false, defaultValue = "10")
            @Min(value = 1, message = "{page.count.min}")
            @Max(value = 30, message = "{page.count.max}") Integer count
    ) {
        return null;
    }

}
